package main

import (
	"fmt"
	"gitee.com/huanminabc/go-utils/cmd"
	"gitee.com/huanminabc/go-utils/ioc"
	"time"
)

type My111Struct struct {
	Name string
	Age  int
}

func NewMy111Struct() My111Struct {
	return My111Struct{
		Name: "huanmin1111",
		Age:  222,
	}
}

type MyStruct struct {
	Name  string
	Age   int
	Test1 My111Struct
}

func NewMyStruct() MyStruct {
	return MyStruct{
		Name: "huanmin",
		Age:  18,
	}
}

func test_cmd_StopHookTasks() {
	cmd.StopHookTasks(&[]func(){
		func() {
			fmt.Println("Ctrl_C")
		},
		func() {
			fmt.Println("Ctrl_C1")
		},
	}, nil)
}
func test_cmd_StopHook() {
	cmd.StopHook(&[]func(){
		func() {
			fmt.Println("Ctrl_C")
		},
		func() {
			fmt.Println("Ctrl_C1")
		},
	})

	time.Sleep(10 * time.Second)
}

func test_ioc() {
	ioc.Provides(NewMyStruct, NewMy111Struct)
	ioc.Bind(func(a int, my MyStruct, my1 MyStruct, my3 *MyStruct, my4 *MyStruct, lf ioc.Lifecycle, lf1 *ioc.Lifecycle) {
		fmt.Println(a)
		fmt.Println(my)
		fmt.Println(my1)
		fmt.Println(my3)
		fmt.Println(my4)
		lf.AddStop(func() {
			fmt.Println("stop")
		})
		lf1.AddStop(func() {
			fmt.Println("stop11")
		})

	})
	time.Sleep(10 * time.Second)
}

func init() {
	ioc.RegisterTestFunc(ioc.TestFuncInfo{
		Name:  "test_cmd_StopHookTasks",
		Fun:   test_cmd_StopHookTasks,
		Start: true,
		Group: "cmd",
	})

	ioc.RegisterTestFunc(ioc.TestFuncInfo{
		Name:  "test_cmd_StopHook",
		Fun:   test_cmd_StopHook,
		Start: true,
		Group: "cmd",
	})
	ioc.RegisterTestFunc(ioc.TestFuncInfo{
		Name:  "test_ioc",
		Fun:   test_ioc,
		Start: true,
		Group: "ioc",
	})
}

func main() {
	ioc.RunTestFuncByName("test_ioc")

}
